package wrap.pages;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HealthTopics.java
 *
 * Created on Nov 21, 2009, 12:23:39 PM
 */

/**
 *
 * @author Lazlo
 */

import java.awt.Dimension;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import wrap.core.*;

public class DOB3 extends javax.swing.JPanel {
    javax.swing.ButtonGroup grpdt1 = new javax.swing.ButtonGroup();
    javax.swing.ButtonGroup grpdt2 = new javax.swing.ButtonGroup();
    javax.swing.ButtonGroup grpyr1 = new javax.swing.ButtonGroup();
    javax.swing.ButtonGroup grpyr2 = new javax.swing.ButtonGroup();
    /** Creates new form HealthTopics */
    public DOB3() {
        initComponents();
        javax.swing.ButtonGroup grp = new javax.swing.ButtonGroup();


        
        grpdt2.add(jToggleButton31);
        grpdt2.add(jToggleButton32);
        grpdt2.add(jToggleButton33);
        
        grpdt2.add(jToggleButton35);
        grpdt2.add(jToggleButton36);
        
        grpdt2.add(jToggleButton38);
        grpdt2.add(jToggleButton39);
        

      
        
        grpyr2.add(jToggleButton14);
        
        grpyr2.add(jToggleButton17);
        
        grpyr2.add(jToggleButton20);



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        Month = new javax.swing.JPanel();
        jPanel13 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel15 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jPanel18 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        Year = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jToggleButton32 = new javax.swing.JToggleButton();
        jToggleButton35 = new javax.swing.JToggleButton();
        jToggleButton38 = new javax.swing.JToggleButton();
        jPanel14 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jToggleButton33 = new javax.swing.JToggleButton();
        jToggleButton36 = new javax.swing.JToggleButton();
        jToggleButton39 = new javax.swing.JToggleButton();
        jToggleButton31 = new javax.swing.JToggleButton();
        Day = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jToggleButton14 = new javax.swing.JToggleButton();
        jToggleButton17 = new javax.swing.JToggleButton();
        jToggleButton20 = new javax.swing.JToggleButton();
        jPanel9 = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.BorderLayout());

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/wrap/sounds/sound.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3, java.awt.BorderLayout.LINE_END);

        jButton4.setText("Back");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton4, java.awt.BorderLayout.LINE_START);

        add(jPanel1, java.awt.BorderLayout.PAGE_START);

        jButton1.setText("Continue");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);

        add(jPanel2, java.awt.BorderLayout.PAGE_END);

        jPanel3.setLayout(new java.awt.BorderLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("To personalize your entertainment, please enter your Date of Birth.");
        jPanel3.add(jLabel1, java.awt.BorderLayout.PAGE_START);

        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        Month.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        Month.setLayout(new java.awt.BorderLayout());

        jPanel13.setLayout(new java.awt.GridLayout(0, 1));

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Month");
        jPanel13.add(jLabel6);

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("---");
        jLabel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel13.add(jLabel7);

        Month.add(jPanel13, java.awt.BorderLayout.PAGE_START);

        jPanel15.setLayout(new java.awt.GridLayout(1, 2));

        jPanel17.setLayout(new java.awt.GridLayout(6, 1));
        jPanel17.add(jLabel12);

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("Select a field to enter");
        jPanel17.add(jLabel13);

        jRadioButton1.setText("Month");
        jRadioButton1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel17.add(jRadioButton1);

        jRadioButton2.setSelected(true);
        jRadioButton2.setText("Day");
        jRadioButton2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel17.add(jRadioButton2);

        jRadioButton3.setText("Year");
        jRadioButton3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel17.add(jRadioButton3);

        jPanel15.add(jPanel17);

        jPanel18.setLayout(new java.awt.GridLayout(6, 1));
        jPanel18.add(jLabel11);

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jPanel18.add(jLabel14);

        jPanel15.add(jPanel18);

        Month.add(jPanel15, java.awt.BorderLayout.CENTER);

        jPanel4.add(Month);

        Year.setLayout(new java.awt.BorderLayout());

        jPanel10.setLayout(new java.awt.GridLayout(0, 1));

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Day");
        jPanel10.add(jLabel4);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("--");
        jLabel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel10.add(jLabel5);

        Year.add(jPanel10, java.awt.BorderLayout.PAGE_START);

        jPanel6.setLayout(new java.awt.GridLayout(1, 3));

        jPanel11.setLayout(new java.awt.GridLayout(0, 1));
        jPanel6.add(jPanel11);

        jPanel12.setLayout(new java.awt.GridLayout(8, 1));
        jPanel12.add(jLabel9);
        jPanel12.add(jLabel16);

        jToggleButton32.setText("1");
        jToggleButton32.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton32ActionPerformed(evt);
            }
        });
        jPanel12.add(jToggleButton32);

        jToggleButton35.setText("4");
        jToggleButton35.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton35ActionPerformed(evt);
            }
        });
        jPanel12.add(jToggleButton35);

        jToggleButton38.setText("7");
        jToggleButton38.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton38ActionPerformed(evt);
            }
        });
        jPanel12.add(jToggleButton38);

        jPanel6.add(jPanel12);

        jPanel14.setLayout(new java.awt.GridLayout(8, 1));
        jPanel14.add(jLabel8);
        jPanel14.add(jLabel17);

        jToggleButton33.setText("2");
        jToggleButton33.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton33ActionPerformed(evt);
            }
        });
        jPanel14.add(jToggleButton33);

        jToggleButton36.setText("5");
        jToggleButton36.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton36ActionPerformed(evt);
            }
        });
        jPanel14.add(jToggleButton36);

        jToggleButton39.setText("8");
        jToggleButton39.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton39ActionPerformed(evt);
            }
        });
        jPanel14.add(jToggleButton39);

        jToggleButton31.setText("0");
        jToggleButton31.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton31ActionPerformed(evt);
            }
        });
        jPanel14.add(jToggleButton31);

        jPanel6.add(jPanel14);

        Year.add(jPanel6, java.awt.BorderLayout.CENTER);

        jPanel4.add(Year);

        Day.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        Day.setLayout(new java.awt.BorderLayout());

        jPanel7.setLayout(new java.awt.GridLayout(0, 1));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Year");
        jPanel7.add(jLabel2);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("19--");
        jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel7.add(jLabel3);

        Day.add(jPanel7, java.awt.BorderLayout.PAGE_START);

        jPanel5.setLayout(new java.awt.GridLayout(1, 3));

        jPanel8.setLayout(new java.awt.GridLayout(8, 1));
        jPanel8.add(jLabel10);
        jPanel8.add(jLabel15);

        jToggleButton14.setText("3");
        jToggleButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton14ActionPerformed(evt);
            }
        });
        jPanel8.add(jToggleButton14);

        jToggleButton17.setText("6");
        jToggleButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton17ActionPerformed(evt);
            }
        });
        jPanel8.add(jToggleButton17);

        jToggleButton20.setText("9");
        jToggleButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton20ActionPerformed(evt);
            }
        });
        jPanel8.add(jToggleButton20);

        jPanel5.add(jPanel8);

        jPanel9.setLayout(new java.awt.GridLayout(0, 1));
        jPanel5.add(jPanel9);
        jPanel5.add(jPanel16);

        Day.add(jPanel5, java.awt.BorderLayout.CENTER);

        jPanel4.add(Day);

        jPanel3.add(jPanel4, java.awt.BorderLayout.CENTER);

        add(jPanel3, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jToggleButton32ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton32ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton32.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();

    }//GEN-LAST:event_jToggleButton32ActionPerformed

    private void jToggleButton36ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton36ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton36.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton36ActionPerformed

    private void jToggleButton38ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton38ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton38.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton38ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        CC.back();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        //Sound
        CC.playPageSound();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(validateDate()){
            CC.getValues().put("Month", jLabel7.getText());
            CC.getValues().put("Day", jLabel5.getText());
            CC.getValues().put("Year", jLabel3.getText());
            CC.to("" + CC.getValues().get("EntertainmentType"));
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private boolean validateDate(){
        // TODO add your handling code here:
        System.out.println("Button"+ jLabel7.getText().length()
                + jLabel3.getText().length()
                +jLabel5.getText().length());

//        if((jLabel7.getText().length() == 0) || (jLabel3.getText().length()==2) || (jLabel5.getText().length()==0))
        if(jLabel3.getText().contains("-") || (jLabel3.getText().length()==3))
        {
            JOptionPane.showMessageDialog(null,  "Please Mention The Year", "Error",JOptionPane.ERROR_MESSAGE);
            return false;
        }

        if(jLabel7.getText().contains("-"))
        {
            JOptionPane.showMessageDialog(null,  "Please Mention The Month", "Error",JOptionPane.ERROR_MESSAGE);
            return false;
        }

        if(jLabel5.getText().contains("-"))
        {
            JOptionPane.showMessageDialog(null,  "Please Mention The Day", "Error",JOptionPane.ERROR_MESSAGE);
            return false;
        }

        if((yearF == "") || (yearL == "") || (dayF == "") || (dayL == ""))
        {
            JOptionPane.showMessageDialog(null,  "Please Enter All Fields", "Error",JOptionPane.ERROR_MESSAGE);
            return false;
        }


        java.util.Map<String,String>  months=new java.util.HashMap<String,String>();

               months.put("Jan", "01");
        months.put("Feb", "02");
        months.put("Mar", "03");
        months.put("Apr", "04");
        months.put("May", "05");
        months.put("Jun", "06");
        months.put("Jul", "07");
        months.put("Aug", "08");
        months.put("Sep", "09");
        months.put("Oct", "10");
        months.put("Nov", "11");
        months.put("Dec", "12");

        String month = months.get(jLabel7.getText());
        String date = month +"/"+ jLabel5.getText() + "/" + jLabel3.getText();
        java.text.SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
        df.setLenient(false);


        System.out.println("This test date:");
        System.out.println(date.toString());

        ParsePosition pp = new ParsePosition(0);
        df.parse(date, pp);
        if(pp.getErrorIndex() > -1) {
            JOptionPane.showMessageDialog(null,  "Please enter a valid date", "Error",JOptionPane.ERROR_MESSAGE);
            return false;
        }
        else
            return true;
    }

    private void bugFix(){
        java.awt.Container cc = this.getParent().getParent();
        java.awt.Container c = this.getParent();
        cc.remove(c);
        cc.validate();
        cc.repaint();
        cc.add(c);
        cc.validate();
        cc.repaint();
    }



    private String dayF = "";
    private String dayL = "";
    private void jToggleButton31ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton31ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton31.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton31ActionPerformed

    private void jToggleButton33ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton33ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton33.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton33ActionPerformed

    private void jToggleButton35ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton35ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton35.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton35ActionPerformed

    private void jToggleButton39ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton39ActionPerformed
        // TODO add your handling code here:
        dayL = jToggleButton39.getText();
        jLabel5.setText(dayF+dayL);
        bugFix();
    }//GEN-LAST:event_jToggleButton39ActionPerformed

    private String yearF = "0";
    private String yearL = "";

    private void jToggleButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton14ActionPerformed
        // TODO add your handling code here:
        yearL = jToggleButton14.getText();
        jLabel3.setText("19" + yearF + yearL);
        bugFix();
    }//GEN-LAST:event_jToggleButton14ActionPerformed

    private void jToggleButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton17ActionPerformed
        // TODO add your handling code here:
        yearL = jToggleButton17.getText();
        jLabel3.setText("19" + yearF + yearL);
        bugFix();
    }//GEN-LAST:event_jToggleButton17ActionPerformed

    private void jToggleButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton20ActionPerformed
        // TODO add your handling code here:
        yearL = jToggleButton20.getText();
        jLabel3.setText("19" + yearF + yearL);
        bugFix();
    }//GEN-LAST:event_jToggleButton20ActionPerformed

private String getText(javax.swing.JLabel lbl1,javax.swing.JToggleButton lbl2,int len)
{
    String val="";
            if(lbl1.getText().length()==len)
            val=lbl1.getText()+ lbl2.getText();
        else if (lbl1.getText().length()==0)
            val= "0"+ lbl2.getText();
        else
            val=lbl1.getText().substring(0,len)  +lbl2.getText();
                    
    return val;
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Day;
    private javax.swing.JPanel Month;
    private javax.swing.JPanel Year;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JToggleButton jToggleButton14;
    private javax.swing.JToggleButton jToggleButton17;
    private javax.swing.JToggleButton jToggleButton20;
    private javax.swing.JToggleButton jToggleButton31;
    private javax.swing.JToggleButton jToggleButton32;
    private javax.swing.JToggleButton jToggleButton33;
    private javax.swing.JToggleButton jToggleButton35;
    private javax.swing.JToggleButton jToggleButton36;
    private javax.swing.JToggleButton jToggleButton38;
    private javax.swing.JToggleButton jToggleButton39;
    // End of variables declaration//GEN-END:variables

}
